// A4.cs
// 
// Copyright (C) 2008 Jean-André Santoni
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
//

using System;
using Cairo;
using System.Collections;
using System.Reflection;
using ChartStyle;

namespace Astrognome
{
	public abstract class A4
	{
		static string appdir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
		
		public static void Draw(Context ctx, Chart chart, Config config, double width, double height)
		{
			ctx.Color = new Color (1, 1, 1);
			ctx.Rectangle(0, 0, width, height);
			ctx.FillPreserve();
			ctx.Clip();
			
			ctx.SelectFontFace("Georgia", FontSlant.Normal, FontWeight.Normal);
			ctx.SetSourceRGB(0.1333, 0.4745, 0.6706);
			ctx.SetFontSize(16);
			ctx.Translate(30, 40);
			ctx.ShowText(chart.ToString());
			ctx.Translate(-30, -40);
			
			ctx.Scale(width/600.0, width/600.0);
			ctx.Translate(0, (height/2.0) - (width/2.0));

			string cs = config.ChartStyle;
			Assembly assembly = Assembly.LoadFrom(appdir + "/modules/"+cs+"/"+cs+".dll");
			
			Hashtable ci = Parser.Parse(chart.AstrologOutput);
			
			foreach(Type type in assembly.GetTypes())
			{
				if(type.Name == "ChartStyle")
				{
					IChartStyle ChartStyle = (IChartStyle) Activator.CreateInstance(type);
					ChartStyle.Draw(ctx, ci);
				}
			}
		}
	}
}
